from datetime import datetime
from django.db import models
from users.models import UserProfileModel
from courses.models import CourseModel


class UserAskModel(models.Model):
    """用户咨询模型"""
    name = models.CharField(verbose_name='姓名', max_length=20)
    mobilie = models.CharField(verbose_name='手机号码', max_length=11)
    course_name = models.CharField(verbose_name='课程名', max_length=100)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '用户咨询'
        verbose_name_plural = verbose_name


class CourseCommentsModel(models.Model):
    """课程评论"""
    user = models.ForeignKey(UserProfileModel, on_delete=models.CASCADE, verbose_name='用户姓名')
    course = models.ForeignKey(CourseModel, on_delete=models.CASCADE, verbose_name='课程')
    comments = models.CharField(verbose_name='评论', max_length=200)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '课程评论'
        verbose_name_plural = verbose_name


class UserFavoriteModel(models.Model):
    """用户收藏"""
    fav_type_data = ((1, '课程'), (2, '课程机构'), (3, '讲师'))

    user = models.ForeignKey(UserProfileModel, on_delete=models.CASCADE, verbose_name='用户姓名')
    fav_id = models.IntegerField(verbose_name='数据id')
    fav_type = models.IntegerField(verbose_name='收藏类型', choices=fav_type_data, default=1)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '用户收藏'
        verbose_name_plural = verbose_name


class UserMessageModel(models.Model):
    """用户消息"""
    user = models.IntegerField(verbose_name='接收用户', default=0)
    message = models.CharField(verbose_name='消息内容', max_length=500, default='')
    has_read = models.BooleanField(verbose_name='是否已读', default=False)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '用户消息'
        verbose_name_plural = verbose_name


class UserCourseModel(models.Model):
    """用户课程"""
    user = models.ForeignKey(UserProfileModel, on_delete=models.CASCADE, verbose_name='用户姓名')
    course = models.ForeignKey(CourseModel, on_delete=models.CASCADE, verbose_name='课程')
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '用户课程'
        verbose_name_plural = verbose_name
